<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>曲线排列</title>
    <style>
        body{
            margin: 0;
            padding: 0;
            background-color: rgba(149, 35, 71, 1);
        }
        div{
            height: 200px;
            color: white;
            text-align: center;
            display: inline-block;
            line-height: 200px;
            margin: 200px;
        }
        span{
            display: inline-block;
        }
    </style>
</head>
<body>
    <div>101010101010101010101010101</div>
</body>
<script>
    //1.把文本分割为 span 元素
    const elem = document.querySelector('div')
    elem.innerHTML = elem.textContent
        .split('')
        .map(m => `<span>${m}</span>`)
        .join('')
    console.log(elem.children);
    //2.计算曲线, 返回曲线y轴值的数组
    function getCurvePoints(curveFunc, range, number){
        if(number < 1){return []}
        if(number === 1){return [0]}
        const piece = (range[1] - range[0]) / (number - 1) //分段,得到x轴的每个点的数值间隔
        const result = []
        for(let i = 0; i<number; i++){
            result.push(-1 * curveFunc(i * piece ))    // -1是为了y轴向上为正
        }
        return result
    }
    const arr = getCurvePoints(x=>30*Math.sin(x), [0, 2*Math.PI], elem.children.length)
    console.log(arr);

    //3.用transform位移形成曲线
    for (let i=0; i<arr.length; i++){
        elem.children[i].style.transform = `translateY(${arr[i]}px)`
    }
</script>
</html>
